<template>
	<view class="jian">
		<button type="primary" v-if="!flag" open-type="getUserInfo" class="subb" @click="gou">微信一键登录</button>
		<button type="primary" v-else open-type="getUserInfo" class="sub" @getuserinfo="login">微信一键登录</button>
		<view class="check">
			<checkbox-group name="" @change="bang">
				<label>
					<checkbox :value="true" /><text>我已阅读并同意《用户协议》和《隐私政策》</text>
				</label>
			</checkbox-group>
		</view>
	</view>
</template>

<script setup>
import {ref
	} from 'vue';
	let flag = ref(false)
	let login = ({
		detail
	}) => {
		uni.login({
			provider: 'weixin',
			success: (key) => {
				uni.setStorageSync('token', key.code)
				uni.setStorageSync('xinxi', detail.userInfo) // 将 nui 改为 uni
				uni.switchTab({
					url: '/pages/my/my',
					success: function(e) {
						const page = getCurrentPages().pop();
						if (page) {
							page.onLoad();
						}
					}
				});
			}
		})
	}
	
	let gou = ()=>{
		uni.showToast({
			title:'请勾选用户协议',
			icon:'none',
		})
	}

	let bang = ({detail})=>{
		detail.value.length ? flag.value = true:flag.value = false
	}
</script>

<style lang="less" scoped>
	.jian {
		width: 90%;
		margin: 50% auto;

		.subb{
			border-radius: 25px;
			background-color: #00CC66;
		}

		.sub {
			border-radius: 25px;
		}
		
		.check{
			width: 90%;
			margin: 20px auto;
			font-size: 13px;
		}
	}
</style>